package peter.study.spring.parsesource.jdbc;

import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import peter.study.spring.parsesource.jdbc.bean.User;
import peter.study.spring.parsesource.jdbc.impl.UserServiceImpl;

public class SpringJDBCTest {

    public static void main(String[] args) {
        // Note: 建立数据连接池需要类KeyedObjectPoolFactory，它在commons-pool.jar中。
        // Note: 连接mysql需要jar包：mysql-connector-java-*.jar，不然找不到驱动com.mysql.jdbc.Driver。
        ApplicationContext ctxt = new ClassPathXmlApplicationContext("peter/study/spring/parsesource/jdbc/jdbc.xml");
        UserServiceImpl service = (UserServiceImpl) ctxt.getBean("userService");
        User user = new User(0, "peter", 27, "M");
        service.save(user);
        List<User> users = service.getUsers();
        System.out.println(user);
        System.out.println(users);
    }

}
